package cn.iocoder.yudao.module.wecom.controller.admin.apiconfig;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import javax.validation.*;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

import cn.iocoder.yudao.module.wecom.controller.admin.apiconfig.vo.*;
import cn.iocoder.yudao.module.wecom.dal.dataobject.apiconfig.WeComApiConfigDO;
import cn.iocoder.yudao.module.wecom.service.apiconfig.WeComApiConfigService;

@Tag(name = "管理后台 - 企业参数配置")
@RestController
@RequestMapping("/wecom/we-com-api-config")
@Validated
public class WeComApiConfigController {

    @Resource
    private WeComApiConfigService weComApiConfigService;

    @GetMapping("/get-corp-auth-url")
    @Operation(summary = "获取企业授权码")
    public CommonResult<String> getCorpAuthUrl() {
        return success(weComApiConfigService.getCorpAuthUrl());
    }

    @GetMapping("/get-contact-auth-url")
    @Operation(summary = "获取通讯录授权码")
    public CommonResult<String> getContactAuthUrl() {
        return success(weComApiConfigService.getContactAuthUrl());
    }

    @GetMapping("/get-acq-auth-url")
    @Operation(summary = "获取获客助手授权码")
    public CommonResult<String> getAcqAuthUrl() {
        return success(weComApiConfigService.getAcqAuthUrl());
    }

    @GetMapping("/get-chat-tool-page")
    @Operation(summary = "获取聊天工具栏页面URL")
    public CommonResult<String> getChatToolPage() {
        return success(weComApiConfigService.getChatToolPageUrl());
    }


    @PostMapping("/bind-data-auth")
    @Operation(summary = "开启会话存档")
    public CommonResult<Boolean> bindDataAuth() {
        weComApiConfigService.bindDataAuth();
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业认证信息")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<WeComApiConfigRespVO> getWeComApiConfig() {
        WeComApiConfigDO weComApiConfig = weComApiConfigService.getWeComApiConfig();
        return success(BeanUtils.toBean(weComApiConfig, WeComApiConfigRespVO.class));
    }

    @GetMapping("/get-jsapi-ticket")
    @Operation(summary = "获得JSApi Ticket信息")
    public CommonResult<String> getWeComJsApiTicket() {
        String jsApiTicket = weComApiConfigService.getWeComJsApiTicket();
        return success(jsApiTicket);
    }

    @PostMapping("/get-jsapi-signature")
    @Operation(summary = "获得JSApi signature 签名")
    public CommonResult<WeComApiSignRespVO> getWeComJsApiSignature(@Valid @RequestBody WeComApiSignReqVO reqVO) {
        WeComApiSignRespVO respVO = weComApiConfigService.getWeComJsApiSignature(reqVO);
        return success(respVO);
    }

    @PostMapping("/edit-msg-save-day")
    @Operation(summary = "更新会话存档记录保存天数")
    public CommonResult<Boolean> editMsgSaveDay(@Valid @RequestBody Integer msgSaveDay) {
        weComApiConfigService.saveMsgSaveDay(msgSaveDay);
        return success(true);
    }

}